package com.tesserate.timecontrol.ui;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;

import com.tesserate.game.api.graphics.Renderable;

public class GLabel extends Canvas implements Renderable{

	private static final long serialVersionUID = 1L;
	private String msg;
	protected FontMetrics fm;
	protected Font font;
	protected Color color;
	protected float alignment = LEFT_ALIGNMENT;
	
	public GLabel(String msg, int x, int y, Font font, Color color){
		this.msg = msg;
		this.setLocation(x, y);
		this.font = font;
		this.color = color;
	}

	public void render(Graphics2D g) {
		g.setFont(font);
		g.setColor(color);
		this.fm = g.getFontMetrics(font);
		int width = fm.stringWidth(this.msg);
		if(alignment == LEFT_ALIGNMENT)
			g.drawString(getMsg(), getX(), getY());
		else
			g.drawString(getMsg(), getX()-width, getY());
		
	}

	public void update(long elapsedTime) {
		// TODO Auto-generated method stub
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public String getMsg() {
		return msg;
	}
	
	public Font getFont() {
		return font;
	}

	public void setFont(Font font) {
		this.font = font;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public float getAlignment() {
		return alignment;
	}

	public void setAlignment(float alignment) {
		this.alignment = alignment;
	}

}
